package com.oro.domain;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

@Entity
public class Authority implements Serializable {

	@Transient
	public static final Authority ADMIN = new Authority("ROLE_ADMIN");

	@Transient
	public static final Authority ANONYMOUS = new Authority("ROLE_ANONYMOUS");
	@Transient
	public static final Authority GUEST = new Authority("ROLE_GUEST");
	@Transient
	public static final Authority OPERATOR = new Authority("ROLE_OPERATOR");
	@Transient
	public static final String ROLE_ADMIN = "ROLE_ADMIN";
	@Transient
	public static final String ROLE_ANONYMOUS = "ROLE_ANONYMOUS";
	@Transient
	public static final String ROLE_GUEST = "ROLE_GUEST";
	@Transient
	public static final String ROLE_OPERATOR = "ROLE_OPERATOR";

	@Transient
	public static final String ROLE_STUDENT = "ROLE_STUDENT";
	@Transient
	public static final String ROLE_SUPERADMIN = "ROLE_SUPERADMIN";
	@Transient
	public static final String ROLE_USER = "ROLE_USER";
	/**
	 * 
	 */
	private static final long serialVersionUID = 12821203656930496L;
	@Transient
	public static final Authority STUDENT = new Authority("ROLE_STUDENT");
	@Transient
	public static final Authority SUPERADMIN = new Authority("ROLE_SUPERADMIN");
	@Transient
	public static final Authority USER = new Authority("ROLE_USER");

	@Transient
	public static final Authority getAuthority(String a) {
		if (a.equals(ROLE_ADMIN))
			return ADMIN;
		else if (a.equals(ROLE_USER))
			return USER;
		else if (a.equals(ROLE_GUEST))
			return GUEST;
		else if (a.equals(ROLE_STUDENT))
			return STUDENT;
		else if (a.equals(ROLE_OPERATOR))
			return OPERATOR;
		else if (a.equals(ROLE_SUPERADMIN))
			return SUPERADMIN;
		else if (a.equals(ROLE_ANONYMOUS))
			return ANONYMOUS;
		else
			return null;
	}

	@Id
	private String role;

	public Authority() {
		super();
	}

	public Authority(String role) {
		this();
		this.role = role;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o != null)
			if (o instanceof Authority)
				return (this.getRole().equals(((Authority) o).getRole()));
			else
				return false;
		else
			return false;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	@Override
	public String toString() {
		return this.role;
	}
}
